// 节流函数
 function throttle(func, time) {
  let timer = null;
  return function (...args) {
    if (!timer) {
      timer = setTimeout(() => {
        timer = null;
        func.apply(this, args);
      }, time);
    }
  };
}
// 时间戳转日期
function time(timestamp) {
  var date = new Date(timestamp);
  var Y = date.getFullYear() + '-';
  var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  var D = date.getDate() + ' ';
  return Y+M+D;
}
// 数字过万处理
function Num (val) {
  let num = 0
  if (val > 9999) {
      num = Math.round(val / 10000 * 10) / 10 + '万'
  } else {
      num = val
  }

  return num
}


//时间戳转换时间
function LstoTime(timestamp) {
  // 时间戳为10位需*1000，时间戳为13位不需乘1000
  var date = new Date(timestamp);
  var Y = date.getFullYear() + "-";
  var M =
    (date.getMonth() + 1 < 10
      ? "0" + (date.getMonth() + 1)
      : date.getMonth() + 1) + "-";
  var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
  var h = date.getHours() + ":";
  var m = date.getMinutes() + ":";
  var s = date.getSeconds();
  return Y + M + D ;
}

function fn(){
  console.log("hhahahha")
}

function Bus(){
  return {
    msg:{},
    on(type, cb){
        if(this.msg[type]){
            this.msg[type].push(cb);
        }else{
            this.msg[type] = [cb];
        }
    },
    emit(type){
        if(!this.msg[type]) return;
        const arg = [...arguments].slice(1);
        this.msg[type].forEach(val=>{
            val(...arg);
        })
    }
} 
}


export default{
  throttle,

  LstoTime,
  fn,
  Bus,

  time,
  Num,
  E:{
    msg:{},
    on(type, cb){
        if(this.msg[type]){
            this.msg[type].push(cb);
        }else{
            this.msg[type] = [cb];
        }
    },
    emit(type){
        if(!this.msg[type]) return;
        const arg = [...arguments].slice(1);
        this.msg[type].forEach(val=>{
            val(...arg);
        })
    }
}

}